package com.loto.insurance.mis.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.loto.insurance.mis.web.authority.INSAuthority;
import com.loto.insurance.mis.web.enumeration.MenuEnum;
import com.loto.insurance.mis.web.enumeration.CustFromEnum;
import com.loto.insurance.mis.web.enumeration.CustExtFromEnum;
import com.loto.insurance.mis.web.enumeration.CustTypeEnum;
import com.loto.insurance.mis.web.enumeration.CustStatusEnum;
import com.loto.insurance.mis.web.service.CustInfoService;

@Controller
public class CustController {
  @Autowired
  CustInfoService custInfoService;

  @INSAuthority(authorityMenu = MenuEnum.CUSTOMER_LIST)
  @RequestMapping(value = "/customer/list", method = RequestMethod.GET)
  public String oemlist(Model model) {
	model.addAttribute("subId", MenuEnum.CUSTOMER_LIST.getIndex());
	return "customer/customer_list";
  }

  @INSAuthority(authorityMenu = MenuEnum.CUSTOMER_LIST)
  @RequestMapping(value = "/customer/detail", method = RequestMethod.GET)
  public String oemdetail(
	  @RequestParam(value = "id", required = false, defaultValue = "-1") long custId,
	  Model model) {
	model.addAttribute("fromList", CustFromEnum.values());
	model.addAttribute("typeList", CustTypeEnum.values());
	model.addAttribute("levelList", custInfoService.findAllLevel());
	model.addAttribute("statusList", CustStatusEnum.values());
	model.addAttribute("extfromList", CustExtFromEnum.values());
	if (custId > 0) {

	  model.addAttribute("cust", custInfoService.findById(custId));
	  model.addAttribute("custExt", custInfoService.findExtById(custId));
	}
	return "customer/customer_detail";
  }
}
